Skip to content

fix(shell): preview Unicode truncation uses byte length instead of char length#29288

Open
LifeJiggy wants to merge 1 commit into
anomalyco:devfrom
LifeJiggy:fix/preview-byte-length
Open

fix(shell): preview Unicode truncation uses byte length instead of char length#29288
LifeJiggy wants to merge 1 commit into
anomalyco:devfrom
LifeJiggy:fix/preview-byte-length

Conversation

@LifeJiggy
Copy link
Copy Markdown

@LifeJiggy LifeJiggy commented May 26, 2026

Issue for this PR

Closes #29291

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The preview() function in shell.ts used text.length (UTF-16 code units) to check if output exceeds the 30,000-byte metadata limit. Multi-byte characters like CJK (3 bytes each) or emoji (4 bytes) were incorrectly counted. The fix uses Buffer.byteLength() for byte-accurate checking and ensures truncated output doesn't split a multi-byte character.

How did you verify your code works?

  • Added a test that generates 12,000 CJK characters (36,000 bytes) and verifies the metadata output contains no Unicode replacement characters
  • Full shell test suite passes (64/66, 2 pre-existing failures unrelated to this change)

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…ar length

The preview function used text.length (UTF-16 code units) to check
if output exceeds the metadata limit, but the actual truncation
should be based on byte length for correct handling of multi-byte
characters (CJK, emoji, etc.). Use Buffer.byteLength for the check
and ensure truncated output does not split a multi-byte character.
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels May 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shell tool preview truncation uses char length instead of byte length

1 participant